package com.woniu.smallmedical.controller;

import com.woniu.smallmedical.entity.Inventory;
import com.woniu.smallmedical.entity.PageBean;
import com.woniu.smallmedical.entity.ResponseResult;
import com.woniu.smallmedical.mapper.BasicmessageMapper;
import com.woniu.smallmedical.mapper.InventoryMapper;
import com.woniu.smallmedical.mapper.StoragemedicineMapper;
import com.woniu.smallmedical.mapper.StoragemessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@CrossOrigin
@RestController
public class InventoryController {

    @Autowired
    StoragemedicineMapper basicmessageapper;
    @Autowired
    InventoryMapper fasicmessageapper;
    @Autowired
    BasicmessageMapper casicmessageapper;
    @Autowired
    StoragemessageMapper dasicmessageapper;
    //添加药品
    //分页查询
    @GetMapping("/Inventorystoragemessage")
    public ResponseResult medicine(Integer pageIndex, Integer pageSize, Integer inid){
        System.out.println("id是："+inid);
        List<Inventory> basicmessages = fasicmessageapper.selectAll(pageIndex,pageSize);
        PageBean<Inventory> pageBean=new PageBean<>();
        pageBean.setPageBeanList(basicmessages);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(fasicmessageapper.selectcount());
        return new ResponseResult<PageBean<Inventory>>(pageBean,200,"OK");
    }




    //分页查询名字
    @GetMapping("/InventorystorageByname")
    public ResponseResult medicineass(Integer pageIndex, Integer pageSize,String name){
        System.out.println("查询的名字是："+name);
        List<Inventory> basicmessages = fasicmessageapper.selectByIds(name,pageIndex,pageSize);
        PageBean<Inventory> pageBean=new PageBean<>();
        pageBean.setPageBeanList(basicmessages);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(fasicmessageapper.selectcount());
        return new ResponseResult<PageBean<Inventory>>(pageBean,200,"OK");
    }


    @GetMapping("/Inventoryselect")
    public Inventory selectmedicine( Integer inid){
        System.out.println("id是："+inid);
        Inventory in=   fasicmessageapper.selectbyinid(inid);
        return in;
    }


    @GetMapping("/queryInventoryAll")
    public ResponseResult queryInventoryAll(String name){
        List<Inventory> basicmessages = fasicmessageapper.queryAll(name);
        return new ResponseResult(basicmessages,200,"OK");
    }


}
